<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<div class="clrboth"></div>
<?php echo $phpJS;?>

<div id="center-wrap" class="ui-corner-tl ui-corner-tr">
	<div id="navigation" class="ui-corner-all"><ul><?php echo $navigator;?></ul></div>
	
	<div class="clrboth"></div>
	
<form action="<?php echo site_url('seller/search');?>" name="my_shows" id="my_shows" method="get" enctype="multipart/form-data" >
	
	<?php 
		$ci=& get_instance();
		
		$country_array = array(''=> 'Country') + countryOriginDataConfig();
		$show_type = array (''=> 'Show Type') + showTypeDataConfig();
		$show_status = array ('' => 'Show Status') + showStatusDataConfig();
		
		$country_dropdown = form_dropdown( 'country_origin',
										$options = $country_array,
										$selected = array( isset($_GET['country_origin'])? $_GET['country_origin']: '' ),
										"class='width70' style='margin-left:10px;'" );
		$show_type_dropdown = form_dropdown( 'show_type',
										$options = $show_type,
										$selected = array( isset($_GET['show_type'])? $_GET['show_type']: '' ),
										"class='width70' style='margin-left:10px;'" );
		$show_status_dropdown = form_dropdown( 'show_status',
										$options = $show_status,
										$selected = array( isset($_GET['show_status'])? $_GET['show_status']: '' ),
										"style='width:105px;margin-left:10px;' " );				
		$title = isset($_GET['title'])? $_GET['title'] : 'Title';									
		$artist = isset($_GET['artist']) ?$_GET['artist'] : 'Artist';
		$bid = isset($_GET['bid']) ? $_GET['bid'] : 'Minimum bid';
		$start_date = isset($_GET['start_date']) ? $_GET['start_date'] : 'From Date';
		$end_date = isset($_GET['end_date']) ? $_GET['end_date'] : 'To Date';
	?>
	
	<div class="row">
		<div class="column grid_9">
			<p class="bold"> &raquo; Search Show:</p>
		</div>
		<div class="clrboth"></div>
		<div class="column grid_9">
			<input type="text" name="title" id="title" value="<?php echo $title;?>" style="width:335px;" />
		
			<?php echo $country_dropdown; ?>
			
			<div class="clrboth"></div>	
			<div style="width:0px;height:10px;"></div>
			
			<input type="text" name="artist" id="artist" value="<?php echo $artist;?>" style="width:220px;" />
		
			<input type="text" name="bid" id="bid" value="<?php echo $bid;?>" class="width70" style="margin-left:10px;width:97px;" />
			
			<?php echo $show_type_dropdown; ?>
			
			<div class="clrboth"></div>	
			<div style="width:0px;height:10px;"></div>
			
			<input type="text" name="start_date" id="start_date" value="<?php echo $start_date;?>" class="width70" />
			
			<input type="text" name="end_date" id="end_date" value="<?php echo $end_date;?>" class="width70" style="margin-left:10px;" />
			 
			<?php echo $show_status_dropdown; ?>
			
			<div class="clrboth"></div>	

			<input type="submit" style="margin-top:20px;" id="button_submit" name="button_submit" value="Search" class="ui-corner-all button-yellow" />
			
			<div class="clrboth"></div>
		</div>
	</div>
	<div class="clrboth"></div>
	
	<div style="width:0px;height:30px;"></div>
	
	<div class="column grid_4">
		<span class="bold" style="float:left;margin-right:15px;">Show</span>
		<?php echo form_dropdown( 'records_per_page',
										$options = showNumberRecordsPerPageDataConfig(),
										$selected = array( isset($_GET['records_per_page'])? $_GET['records_per_page']: defaultNumberRecordsPerPageShowDataConfig() ),
										"id='records_per_page' onchange='javascript:change_num_per_page(this.value);' style='float:left;' " );
		?>
		&nbsp;
		<?php 
			$num_results = $items['total_records'];
			if( $num_results > 1 ){
				echo " of ". $num_results." records.";
			}else if( $num_results == 1 ){
				echo " of ". $num_results." record.";
			}
		?>
	</div>
	
	<div class="column grid_5">
		<div id="pagination">
			<?php 
				echo $items['pagination']['links'];
			?>
		</div>
	</div> 
	
	<div class="clrboth"></div>
	<div id="result_display">
		<table>
			<thead>
				<td width="100px">Show Ref</td>
				<td width="200px">Artist</td>
				<td width="200px">Show Date</td>
				<td width="100px">Bid Due Date</td>
				<td width="100px">Status</td>
				<td width="250px">Action</td>
			</thead>
			<tbody>
			 
				<?php if(!empty($items['items'])):?>
					<?php foreach($items['items'] as $object):?>
						<?php $SHOW = $ci->show_entity->init('id', $object->id) ;?>
						<tr>
							<td><?php echo $SHOW->getRefNo();?></td>
							<td><?php echo $SHOW->getArtist();?></td>
							<td><?php echo sbxDateFormat($SHOW->getStartDate(),'d/M/Y')." - ".sbxDateFormat($SHOW->getEndDate(),'d/M/Y');?></td>
							<td><?php echo sbxDateFormat($SHOW->getBidDueDate(), 'd/M/Y');?></td>
							<td><?php echo $show_status[$SHOW->getStatus()];?></td>
							<td>
								<a class="manage ui-corner-all" href="<?php echo site_url('seller/show_manage/view_edit?show_id='.$SHOW->getId());?>">Edit</a>
								&nbsp;&nbsp;&nbsp;
								<a class="manage ui-corner-all" href="<?php echo site_url('seller/show_manage/bid?show_id='.$SHOW->getId());?>">Manage Bids</a>
							</td>
						</tr>
					<?php endforeach; ?>
				<?php endif; ?>
			</tbody>
		</table>
	</div>
	
	<div class="clrboth"></div>
	
	<div class="column grid_4">
		<span class="bold" style="float:left;margin-right:15px;">Show</span>
		<?php echo form_dropdown( 'records_per_page',
										$options = showNumberRecordsPerPageDataConfig(),
										$selected = array( isset($_GET['records_per_page'])? $_GET['records_per_page']: '' ),
										"id='records_per_page' onchange='javascript:change_num_per_page(this.value);' style='float:left;' " );
		?>
		&nbsp;
		<?php 
			$num_results = $items['total_records'];
			if( $num_results > 1 ){
				echo " of ". $num_results." records.";
			}else if( $num_results == 1 ){
				echo " of ". $num_results." record.";
			}
		?>
	</div>
	
	<div class="column grid_5">
		<div id="pagination">
			<?php 
				echo $items['pagination']['links'];
			?>
		</div>
	</div> 
	
	<div class="clrboth"></div>
	<div style="width:0px;height:30px;"></div>
	<div class="clrboth"></div>
</form>	
</div>
<div class="clrboth"></div>

<script type="text/javascript">
	$(function(){
		$( "#start_date" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'd-M-yy'
		});
		
		$( "#end_date" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'd-M-yy'
		});
		
		$('#title').click(function(){
			if($(this).val() == 'Title'){
				$(this).attr('value','');
			}
		});
		$('#title').bind('focusout',function(){
			if($(this).val() == ''){
				$(this).attr('value','Title');
			}
		});
		
		$('#artist').click(function(){
			if($(this).val() == 'Artist'){
				$(this).attr('value','');
			}
		});
		$('#artist').bind('focusout',function(){
			if($(this).val() == ''){
				$(this).attr('value','Artist');
			}
		});
		
		$('#bid').click(function(){
			if($(this).val() == 'Minimum bid'){
				$(this).attr('value','');
			}
		});
		$('#bid').bind('focusout',function(){
			if($(this).val() == ''){
				$(this).attr('value','Minimum bid');
			}
		});
		
		$('#start_date').click(function(){
			if($(this).val() == 'From Date'){
				$(this).attr('value','');
			}
		});
		$('#start_date').bind('focusout',function(){
			if($(this).val() == ''){
				$(this).attr('value','From Date');
			}
		});
		
		$('#end_date').click(function(){
			if($(this).val() == 'To Date'){
				$(this).attr('value','');
			}
		});
		$('#end_date').bind('focusout',function(){
			if($(this).val() == ''){
				$(this).attr('value','To Date');
			}
		});
	});
	function change_num_per_page(value){
		__GET.records_per_page = value;
		__GET.per_page = "";
		_makeQueryURL();
	}
</script>
